home *** CD-ROM | disk | FTP | other *** search
/ MacWorld: Conference & Expo 2005 / Macworld Conference and Expo - Documentation CD-ROM (2004).iso / mac / Adobe Reader 6.0 / Adobe Reader 6.0.app / Contents / MacOS / JavaScripts / Annots.js < prev    next >
Text File  |  2004-01-30  |  41KB  |  1,616 lines

  1. var AcroPlugins = app.plugIns;
  2. var annotsPresent = false;
  3.  
  4. for (var iAcroPlugins = 0; iAcroPlugins < AcroPlugins.length ; iAcroPlugins++)
  5.     if (AcroPlugins[iAcroPlugins].name.toLowerCase() == "annots")
  6.     {
  7.         annotsPresent = true;
  8.         break;
  9.     }
  10.  
  11. if (annotsPresent)
  12. {
  13.     var strsToExport = new Array (
  14.         "IDS_SUM_TITLE1",
  15.         "IDS_SUM_TITLE2",
  16.         "IDS_UNNAMED",
  17.         "IDS_SUM_DATE1",
  18.         "IDS_SUM_DATE2",
  19.         "IDS_SUM_AUTHOR1",
  20.         "IDS_SUM_AUTHOR2",
  21.         "IDS_SUM_SUBJ1",
  22.         "IDS_SUM_SUBJ2",
  23.         "IDS_SUM_LABEL1",
  24.         "IDS_SUM_LABEL2",
  25.         "IDS_SUM_PAGE1",
  26.         "IDS_SUM_PAGE2",
  27.         "IDS_SUM_TYPE1",
  28.         "IDS_SUM_TYPE2",
  29.         "IDS_SUM_SEQ1",
  30.         "IDS_SUM_SEQ2",
  31.         "IDS_SUM_NO_ANNOTS1",
  32.         "IDS_SUM_NO_ANNOTS2",
  33.         "IDS_STORE_WEB_DISCUSSIONS",
  34.         "IDS_STORE_DAVFDF",
  35.         "IDS_STORE_FSFDF",
  36.         "IDS_STORE_DATABASE",
  37.         "IDS_STORE_NONE",
  38.         "IDS_PROGRESS_SUMMARIZE",
  39.         "IDS_PROGRESS_SORTING",
  40.         "IDS_PROGRESS_FETCHING",
  41.         "IDS_PROGRESS_FETCHING_BIG",
  42.         "IDS_PROGRESS_ADDING",
  43.         "IDS_PROGRESS_DELETING",
  44.         "IDS_PROGRESS_CHANGING",
  45.         "IDS_ANNOTS_JS_BUILTIN",
  46.         "IDS_DATE_INDETERMINATE",
  47.         "IDS_EMAIL_PLEASE",
  48.         "IDS_EMAIL_BLANKNAME",
  49.         "IDS_EMAIL_VERIFY",
  50.         "IDS_EMAIL_TITLE",
  51.         "IDS_EMAIL_LABEL",
  52.         "IDS_SEND_FOR_REVIEW_SUBJ",
  53.         "IDS_SEND_FOR_REVIEW_MSG",
  54.         "IDS_SEND_FOR_REVIEW_MSG_LABEL",
  55.         "IDS_SEND_FOR_REVIEW",
  56.         "IDS_SEND_FOR_REVIEW_TITLE",
  57.         "IDS_SEND_FOR_REVIEW_TITLE_NONAME",
  58.         "IDS_SEND_FOR_REVIEW_INST1",
  59.         "IDS_SEND_FOR_REVIEW_INST2",
  60.         "IDS_SEND_FOR_REVIEW_GET_ADDRS_CAPTION",
  61.         "IDS_SEND_FOR_REVIEW_VERSION_ERR",
  62.         "IDS_SEND_FOR_REVIEW_CONFIRM_MSG",
  63.         "IDS_SEND_FOR_REVIEW_CONFIRM_TIP",
  64.         "IDS_SEND_FOR_REVIEW_CONFIRM_TITLE",
  65.         "IDS_SEND_FOR_REVIEW_PROBLEM",
  66.         "IDS_SEND_FOR_REVIEW_NO_RECIPIENT",
  67.         "IDS_SEND_COMMENTS_TO_AUTHOR_TITLE",
  68.         "IDS_SEND_COMMENTS_TO_AUTHOR_TO",
  69.         "IDS_SEND_COMMENTS_TO_AUTHOR_SUBJ",
  70.         "IDS_SEND_COMMENTS_TO_AUTHOR_MSG",
  71.         "IDS_SEND_COMMENTS_TO_AUTHOR_MSG_LABEL",
  72.         "IDS_SEND_COMMENTS_TO_AUTHOR_INST1",
  73.         "IDS_SEND_COMMENTS_TO_AUTHOR_INST2",
  74.         "IDS_SEND_COMMENTS_TO_AUTHOR_CONFIRM",
  75.         "IDS_SEND_COMMENTS_TO_AUTHOR",
  76.         "IDS_COLLAB_TITLE",
  77.         "IDS_ACTION_REVIEW",
  78.         "IDS_STATE_NONE",
  79.         "IDS_STATE_ACCEPT",
  80.         "IDS_STATE_REJECT",
  81.         "IDS_STATE_CANCELLED",
  82.         "IDS_STATE_COMPLETED",
  83.         "IDS_ACTION_COLLAB",
  84.         "IDS_STATE_COLLAB_ACTIVE",
  85.         "IDS_STATE_COLLAB_COMPLETED",
  86.         "IDS_ACTION_MARKED",
  87.         "IDS_STATE_MARKED",
  88.         "IDS_STATE_UNMARKED",
  89.         "IDS_SUM_FOOTER1",
  90.         "IDS_SUM_FOOTER2",
  91.         "IDS_SUM_STATUS_TITLE",
  92.         "IDS_SEND_FOR_REVIEW_DOC_IS_DIRTY",
  93.         "IDS_EMAIL_INVALID",
  94.         "IDS_SEND_COMMENTS_ATTACHMENT",
  95.         "IDS_SEND_FOR_REVIEW_ATTACHMENT"
  96.     );
  97.  
  98.     for(var nToExport = 0; nToExport < strsToExport.length; nToExport++)
  99.     {
  100.         var strID = strsToExport[nToExport];
  101.  
  102.         eval(strID + " = " + app.getString("Annots", strID).toSource());
  103.     }
  104.  
  105.     console.println(IDS_ANNOTS_JS_BUILTIN);
  106.  
  107.     /* for debugging */
  108.     function debugExcept(e)
  109.     {
  110.         if((typeof app._DEBUG != "undefined") && app._DEBUG)
  111.           console.println(e)
  112.     }
  113.  
  114.     /* Sort methods */
  115.     ANSB_None = 0;
  116.     ANSB_Page = 1;
  117.     ANSB_Seq = 2;
  118.     ANSB_Author = 3;
  119.     ANSB_ModDate = 4;
  120.     ANSB_Type = 5;
  121.     ANSB_Subject = 6;
  122.  
  123.     ANFB_ShouldPrint = 0;
  124.     ANFB_ShouldView = 1;
  125.     ANFB_ShouldEdit = 2;
  126.     ANFB_ShouldAppearInPanel = 3;
  127.     ANFB_ShouldSummarize = 4;
  128.     ANFB_ShouldExport = 5;
  129.     ANFB_ShouldCollaborate = 6;
  130.     ANFB_ShouldNone = 7;
  131.  
  132.     /* Field to summary functions by property name */
  133.     ANsums =
  134.     [
  135.     /* None */        function(a){return "*None*";},
  136.     /* Page */        function(a){return IDS_SUM_PAGE1+a.doc.getPageLabel(a.page)+IDS_SUM_PAGE2;},
  137.     /* Sequence */    function(a, s){return IDS_SUM_SEQ1+(s ? s : a.seqNum)+IDS_SUM_SEQ2;},
  138.     /* Author */    function(a){return IDS_SUM_AUTHOR1+a.author+IDS_SUM_AUTHOR2;},
  139.     /* ModDate */    function(a){
  140.         var d = a.modDate; 
  141.         return IDS_SUM_DATE1+ (d ? util.printd(2, a.modDate) : IDS_DATE_INDETERMINATE )+IDS_SUM_DATE2;
  142.         },
  143.     /* Type */        function(a){return IDS_SUM_TYPE1+a.uiType+IDS_SUM_TYPE2;},
  144.     /* Subject */    function(a){
  145.         var s = a.subject;
  146.         return s ? IDS_SUM_SUBJ1+s+IDS_SUM_SUBJ2 : "";
  147.         },
  148.     ];
  149.  
  150.     /* Order of summary fields */
  151.     ANsumorder = [ ANSB_Page, ANSB_Author, ANSB_Subject, ANSB_ModDate ];
  152.  
  153.     /* binary insertion into sorted list */
  154.     function binsert(a, m)
  155.     {
  156.         var nStart = 0, nEnd = a.length - 1;
  157.  
  158.         while(nStart < nEnd)
  159.         {
  160.             var nMid = Math.floor((nStart + nEnd) / 2);
  161.  
  162.             if(m.toString() < a[nMid].toString())
  163.                 nEnd = nMid - 1;
  164.             else
  165.                 nStart = nMid + 1;
  166.         }
  167.         if((nStart < a.length) && (m.toString() >= a[nStart].toString()))
  168.             a.splice(nStart + 1, 0, m);
  169.         else
  170.             a.splice(nStart, 0, m);
  171.     }
  172.  
  173.     /* perform a worst case n log ( n ) sort with status */
  174.     function isort(a, status)
  175.     {
  176.         var i;
  177.         var aNew = new Array();
  178.  
  179.         if(status)
  180.         {
  181.             app.thermometer.begin();
  182.             app.thermometer.duration = a.length;
  183.             app.thermometer.text = status;
  184.         }
  185.         for(i = 0; i < a.length; i++)
  186.         {
  187.             if(status)
  188.                 app.thermometer.value = i;
  189.             binsert(aNew, a[i]);
  190.         }
  191.         if(status)
  192.             app.thermometer.end();
  193.         return aNew;
  194.     }
  195.  
  196.     function ANstateful(annot)
  197.     {
  198.       return annot &&
  199.         typeof annot.state == "object" &&
  200.         typeof annot.state.state != "undefined" &&
  201.         annot.state.state;
  202.     }
  203.  
  204.     function ANsumFlatten(a, m, i, s)
  205.     {
  206.         var result = [];
  207.  
  208.         if(a)
  209.         {
  210.             if(s)
  211.                 /* if we're sorting, sort by creation date */
  212.                 a.sort(function(a,b){
  213.                     return a.creationDate.getTime() - b.creationDate.getTime();
  214.                 });
  215.  
  216.             for(var n = 0; n < a.length; n++)
  217.             {
  218.                 var item = a[n];
  219.  
  220.                 result.push(item); /* push on the item */
  221.                 result.push(i); /* the indent level */
  222.  
  223.                 // don't indent if this one is stateful
  224.                 var sub = ANsumFlatten(m[item.name], m, i + (ANstateful(item) ? 0 : 1), true);
  225.  
  226.                 for(var j = 0; j < sub.length; j++)
  227.                     result.push(sub[j]); /* and the sub stuff */
  228.             }
  229.         }
  230.         return result;
  231.     }
  232.  
  233.     function ANsummAnnot(annot, scale, doc, r, p, seqNum)
  234.     {
  235.       var assoc = true;
  236.  
  237.       r.size = 1 * scale;
  238.  
  239.          if(seqNum && !annot.inReplyTo)
  240.         r.writeText(ANsums[ANSB_Seq](annot, seqNum), doc, annot.page, annot.rect, false, "" + seqNum, annot.containedPopupHeelPoint);
  241.  
  242.          for(j = 0; j < ANsumorder.length; j++)
  243.              if(ANsumorder[j] != p)
  244.              {
  245.                  var s = (ANsums[ANsumorder[j]])(annot);
  246.    
  247.                  if(s)
  248.                  {
  249.                   if(assoc)
  250.                   {
  251.                     assoc = false;
  252.                      if(!annot.inReplyTo && !seqNum)
  253.                     r.writeText(s, doc, annot.page, annot.rect);
  254.                      else
  255.                        r.writeText(s, doc, annot.page);
  256.                   }
  257.                   else
  258.                     r.writeText(s, doc, annot.page);
  259.                  }
  260.              }
  261.  
  262.       var contents = annot.richContents;
  263.  
  264.       if(contents)
  265.       {
  266.           r.style = "DefaultNoteText";
  267.           r.indent({nAmount: 16 * scale, oIcon: annot.uiIcon, color: annot.strokeColor});
  268.           r.writeText(contents, doc, annot.page);
  269.           r.writeText(" ", doc, annot.page);
  270.           r.outdent(16 * scale);
  271.       }
  272.       else
  273.       {
  274.           r.indent({nAmount: 16 * scale, oIcon: annot.uiIcon, color: annot.strokeColor});
  275.           r.writeText(" ", doc, annot.page);
  276.           r.writeText(" ", doc, annot.page);
  277.           r.outdent(16 * scale);
  278.       }
  279.  
  280.       // Add the state info
  281.       var models = Collab.getStateModels(false);
  282.       for(i = 0; i < models.length; i++)
  283.       {
  284.           var states = annot.getStateInModel(models[i].name);
  285.  
  286.           if(states.length > 0)
  287.           {
  288.               r.writeText("" + IDS_SUM_STATUS_TITLE, doc, annot.page);
  289.  
  290.               for(j = 0; j < states.length; j++)
  291.               {
  292.                 var d = util.printd(2, states[j].modDate);
  293.                 var s = states[j].state;
  294.                 var a = states[j].author;
  295.  
  296.                   r.writeText(a + " " + s + " " + d, doc, annot.page);
  297.             }
  298.           }
  299.       }
  300.     }
  301.  
  302.     function ANsummarize(doc, title, p, r, dest, fs, print, twoUp, useSeqNum, scale, noAssocDoc, filter)
  303.     {    /* Summarize annotations sorted primarily by property p */
  304.         if(!scale)
  305.             scale = 1;
  306.  
  307.         var thermoUp = true;
  308.         app.thermometer.begin();
  309.  
  310.         try
  311.         {
  312.             app.thermometer.text = IDS_PROGRESS_SUMMARIZE;
  313.  
  314.             if(!ANsums[p])
  315.                 p = ANSB_Page;
  316.             if(!title)
  317.                 title = IDS_UNNAMED;
  318.  
  319.             /* make sure we have all annots */
  320.             this.syncAnnotScan();
  321.  
  322.             /* Get all summarizable annots on all pages sorted in the given manner */
  323.             var a = [];
  324.  
  325.             for(var n = 0; n < doc.numPages; n++)
  326.             {
  327.               var a2 = doc.getAnnots(n, p, r, typeof filter == "undefined" ? ANFB_ShouldSummarize : filter);
  328.  
  329.               for(var n2 = 0; a2 && n2 < a2.length; n2++)
  330.               {
  331.                   // If it's hidden, or a state annot (or both) don't show it
  332.                   var curAnnot = a2[n2];
  333.  
  334.                   if(!curAnnot.hidden && (!curAnnot.state || !curAnnot.state.state))
  335.                     a.push(curAnnot);
  336.               }
  337.             }
  338.  
  339.             if(a && a.length > 0) /* Put in thread order */ 
  340.             {
  341.                 app.thermometer.duration = a.length * 4;
  342.  
  343.                 var t = {};
  344.  
  345.                 for(var n = 0; n < a.length; n++, app.thermometer.value = n * 2)
  346.                 {
  347.                     var item = a[n];
  348.  
  349.                     if(!t[item.inReplyTo])
  350.                         t[item.inReplyTo] = [ item ];
  351.                     else
  352.                         t[item.inReplyTo].push(item);
  353.                 }
  354.  
  355.  
  356.                 /* don't sort the top level 'cuz it's already sorted */
  357.                 a = ANsumFlatten(t[""], t, 0, false);
  358.  
  359.                 /* make the indents differential */
  360.                 for(var j = a.length - 1; j > 2; j -= 2)
  361.                     a[j] -= a[j - 2];
  362.             }
  363.  
  364.             var t;
  365.             var r = new Report();
  366.             var assocDoc = noAssocDoc ? null : doc;
  367.  
  368.             r.ignoreAnnotLayers = (filter == ANFB_ShouldNone);
  369.             r.joinAssocs = twoUp;
  370.             r.style = "NoteTitle";
  371.             r.size = 3 * scale;
  372.             t = IDS_SUM_TITLE1 + title + IDS_SUM_TITLE2;
  373.             r.writeText(t);
  374.             r.divide(3.5 * scale);
  375.  
  376.             var i, j, contents;
  377.             var oldHeading;
  378.             var lastAnnotPage;
  379.             var curFooterText = "";
  380.             var seqNum = 1;
  381.  
  382.             if(a && a.length > 0)
  383.             {
  384.               for(i = 0; i < a.length; i += 2)
  385.               {
  386.                 app.thermometer.value = a.length + i;
  387.  
  388.                 // update the indent level
  389.                 var ind = a[i + 1];
  390.                 var curAnnot = a[i];
  391.                 var footerText = "";
  392.  
  393.                 // update the footer
  394.                   r.style = "NoteTitle";
  395.                   r.size = 2 * scale;
  396.                 if((typeof lastAnnotPage != "undefined") && (curAnnot.page != lastAnnotPage))
  397.                 {
  398.                     footerText = curFooterText = "";
  399.                     r.setFooterText();
  400.                     r.breakPage();
  401.                     seqNum = 1;
  402.                 }
  403.  
  404.                 footerText = "\r" + IDS_SUM_FOOTER1 + doc.getPageLabel(curAnnot.page) + IDS_SUM_FOOTER2; 
  405.  
  406.                 if(footerText != curFooterText)
  407.                 {
  408.                     curFooterText = footerText;
  409.                     r.setFooterText(footerText);
  410.                 }
  411.  
  412.                 for(; ind < 0; ind++)
  413.                     { r.outdent(16 * scale); r.outdent(16 * scale); }
  414.                 for(; ind > 0; ind--)
  415.                     { r.indent(16 * scale); r.indent(16 * scale); }
  416.  
  417.                 // maybe do the heading
  418.                   var heading = (ANsums[p])(curAnnot);
  419.                   if(heading != oldHeading)
  420.                   {
  421.                     if(typeof oldHeading != "undefined")
  422.                       r.writeText(" ");
  423.                     r.writeText(heading, assocDoc, curAnnot.page);
  424.                     oldHeading = heading;
  425.                     r.divide();
  426.                   }
  427.  
  428.                 if(useSeqNum)
  429.                     ANsummAnnot(curAnnot, scale, assocDoc, r, p, seqNum);
  430.                 else
  431.                     ANsummAnnot(curAnnot, scale, assocDoc, r, p);
  432.  
  433.                 if(!curAnnot.inReplyTo)
  434.                     seqNum++;
  435.  
  436.                   r.divide(1 * scale);
  437.                   lastAnnotPage = curAnnot.page;
  438.               }
  439.               r.setFooterText();
  440.             }
  441.             else
  442.               r.writeText(IDS_SUM_NO_ANNOTS1 + title + IDS_SUM_NO_ANNOTS2);
  443.  
  444.             if(thermoUp)
  445.             {
  446.                 thermoUp = false;
  447.                 app.thermometer.end();
  448.             }
  449.  
  450.             if (typeof dest != "undefined")
  451.                 r.save(dest, fs);
  452.             else if(print)
  453.                 r.print();
  454.             else
  455.                 r.open(t);
  456.         }
  457.         catch(e)
  458.         {
  459.             app.alert({cMsg: e["message"], oDoc: doc});
  460.         }
  461.         if(thermoUp)
  462.             app.thermometer.end();
  463.  
  464.         return a ? a.length / 2 : 0;
  465.     }
  466. }
  467.  
  468. if(typeof Collab != "undefined")
  469. {
  470.     /* flags used by collaboration
  471.     */
  472.     CBFNiceTableName = 1;
  473.     CBFNiceDBName = 2;
  474.     CBFDBPerDoc = 4;
  475.  
  476.     function CBgetTableDesc(doc, author)
  477.     {
  478.       var frag = Collab.URL2PathFragment(doc.URL);
  479.       var DBName;
  480.       var tableName;
  481.  
  482.       if(doc.collabDBFlags & CBFDBPerDoc)
  483.       {
  484.         DBName = frag;
  485.         tableName = author;
  486.       }
  487.       else
  488.       {
  489.         DBName = "";
  490.         tableName = frag;
  491.       }
  492.  
  493.       if(doc.collabDBFlags & CBFNiceTableName)
  494.         tableName = Collab.hashString(tableName);
  495.       if(doc.collabDBFlags & CBFNiceDBName)
  496.         DBName = Collab.hashString(DBName);
  497.       return {DBName: DBName ? doc.collabDBRoot + DBName : doc.collabDBRoot,
  498.         tableName: tableName,
  499.         URL: doc.URL,
  500.         user: author,
  501.         flags: doc.collabDBFlags};
  502.     }
  503.  
  504.     function CBgetTableConnect(desc)
  505.     {
  506.       var e;
  507.  
  508.       try
  509.       {
  510.         var conn = ADBC.newConnection(desc.DBName);
  511.         var stmt = conn.newStatement();
  512.  
  513.         return {conn: conn,
  514.           stmt: stmt,
  515.           tableName: desc.tableName,
  516.           user: desc.user,
  517.           flags: desc.flags};
  518.       }
  519.       catch(e) { debugExcept(e); return false; }
  520.     }
  521.  
  522.     function CBgetInfo(conn, name)
  523.     {
  524.       var e;
  525.  
  526.       try
  527.       {
  528.         conn.stmt.execute("select CONTENTS from \"" + conn.tableName + "\" where AUTHOR like ?;",
  529.           "~" + name + "~");
  530.         conn.stmt.nextRow();
  531.         return conn.stmt.getColumn("CONTENTS").value;
  532.       }
  533.       catch(e) { debugExcept(e); return false; }
  534.     }
  535.  
  536.     function CBsetInfo(conn, name, value)
  537.     {
  538.       var e;
  539.  
  540.       /* add the field */
  541.       try { return conn.stmt.execute("insert into \"" + conn.tableName + "\" (AUTHOR, CONTENTS) values (?, ?);",
  542.           "~" + name + "~",
  543.           value); }
  544.       catch(e) { debugExcept(e); return false; }
  545.     }
  546.  
  547.     function CBcreateTable(desc)
  548.     {
  549.       var e;
  550.  
  551.       try
  552.       {
  553.         var conn = ADBC.newConnection(desc.DBName);
  554.         var stmt = conn ? conn.newStatement() : null;
  555.  
  556.         /* come up with the SQL query to do it */
  557.         var sql1 = "create table \"" + desc.tableName + "\" (AUTHOR varchar(64), PAGE integer, NAME varchar(64), CONTENTS text, DATA image);";
  558.         var sql2 = "create table \"" + desc.tableName + "\" (AUTHOR varchar(64), PAGE integer, NAME varchar(64), CONTENTS clob, DATA blob);";
  559.  
  560.         var conn = {conn: conn,
  561.           stmt: stmt,
  562.           tableName: desc.tableName,
  563.           user: desc.user,
  564.           flags: desc.flags};
  565.  
  566.         // first try...
  567.         try
  568.         {
  569.           stmt.execute(sql1);
  570.         } catch(e) { debugExcept(e); }
  571.         // second try...
  572.         try
  573.         {
  574.           stmt.execute(sql2);
  575.         } catch(e) { debugExcept(e); }
  576.         // these will throw if the table wasn't created
  577.         CBsetInfo(conn, "URL", desc.URL);
  578.         CBsetInfo(conn, "creator", desc.user);
  579.         return conn;
  580.       }
  581.       /* we failed... */
  582.       catch(e) { debugExcept(e); return false; }
  583.     }
  584.  
  585.     function CBconnect(desc, bDoNotCreate)
  586.     {
  587.       var conn = CBgetTableConnect(desc);
  588.       var e;
  589.  
  590.       /* if we can't get the URL from it, it doesn't exist */
  591.       if(!CBgetInfo(conn, "URL"))
  592.       {
  593.         if (!bDoNotCreate)
  594.           conn = CBcreateTable(desc);
  595.         else
  596.           return false;
  597.       }
  598.  
  599.       /* here it is! */
  600.       return conn;
  601.     }
  602.  
  603.     /* mapping of annot types to data properties */
  604.     CBannotdata =
  605.     {
  606.         FileAttachment:    function(p) { return "FSCosObj" },
  607.         Sound:            function(p) { return "SCosObj" },
  608.         Stamp:            function(p) { return /^\#/.exec(p.AP) ? "APCosObj" : false }
  609.     };
  610.  
  611.     /* returns the data fork for an annot */
  612.     function CBannotData(annot)
  613.     {
  614.       var prop = CBannotdata[annot.type];
  615.       if(prop != null)
  616.       {
  617.           prop = prop(annot);
  618.           var stm = prop ? Collab.cosObj2Stream(annot[prop]) : null;
  619.  
  620.           if(stm && typeof ADBC != "undefined") 
  621.             stm.type = ADBC.SQLT_LONGVARBINARY;
  622.           return stm;
  623.       }
  624.     }
  625.  
  626.     /* sets the data fork of an annot */
  627.     function CBannotSetData(annot, data)
  628.     {
  629.       var prop = CBannotdata[annot.type];
  630.       if(prop)
  631.       {
  632.           prop = prop(annot);
  633.           if(prop) annot[prop] = data;
  634.       }
  635.     }
  636.  
  637.  
  638.     /* recursive function that deletes a reply chain */
  639.     function CBDeleteReplyChain(disc)
  640.     {
  641.         var replies = Discussions.getDiscussions(disc);
  642.  
  643.         if (replies && (replies.length == 1))
  644.         {
  645.             var currentReply = replies[0];
  646.             var looper = 1;
  647.             while (looper)
  648.             {
  649.                 /*
  650.                 ** There better only be one reply 
  651.                 */
  652.                 var saveChild = Discussions.getDiscussions(currentReply);
  653.  
  654.     //            console.println("Delete reply");
  655.                 currentReply.Delete();
  656.  
  657.                 if (saveChild && (saveChild.length == 1))
  658.                     currentReply = saveChild[0];
  659.                 else
  660.                     looper = 0;
  661.             }
  662.         }
  663.  
  664.     }
  665.  
  666.     /* gets the reply chain, stuffs it in a stream */
  667.     /* and then puts it in the annot */
  668.     function CBGetReplyChain(dstAnnot, discussion)
  669.     {
  670.         var discList = Discussions.getDiscussions(discussion);
  671.  
  672.         var cos = Collab.newWrStreamToCosObj();
  673.  
  674.         var data = 0;
  675.         while (discList && (discList.length > 0))
  676.         {
  677.             data = 1;
  678.             cos.write(discList[0].Text);
  679.             //console.println("Write to cos stream " + discList[0].Text.length + " characters");
  680.  
  681.             discList = Discussions.getDiscussions(discList[0]);
  682.         }
  683.  
  684.         if (data == 1)
  685.             CBannotSetData(dstAnnot, cos.getCosObj());
  686.     }
  687.  
  688.     /* get the stream and puts the data as replies */
  689.     function CBPutReplyChain(discussion, bookmark, srcAnnot)
  690.     {
  691.         var cosStream = CBannotData(srcAnnot);
  692.  
  693.         if(cosStream)
  694.         {
  695.             var s = cosStream.read(Collab.wdBlockSize);
  696.  
  697.             while (discussion && (s.length > 0))
  698.             {
  699.                 discussion = Discussions.addDiscussion(discussion, "Data", s, bookmark);
  700.  
  701.                 s = null;
  702.             
  703.                 s = cosStream.read(Collab.wdBlockSize);
  704.             }
  705.         }
  706.     }
  707.  
  708.     /* ADBC based annot enumerator constructor
  709.     */
  710.     function ADBCAnnotEnumerator(parent, sorted)
  711.     {
  712.       /* store away parameters */
  713.       this.parent = parent;
  714.       this.sorted = sorted;
  715.       /* add enumeration method */
  716.       this.next = function()
  717.       {
  718.         var e;
  719.  
  720.         try
  721.         {
  722.           if(!this.conn)
  723.           {
  724.             this.conn = CBconnect(this.parent.desc, true);
  725.             this.conn.stmt.execute("select CONTENTS from \"" + this.parent.desc.tableName + "\" where AUTHOR not like '~%~'" +
  726.               (this.sorted ? " order by PAGE, NAME;" : ";"));
  727.           }
  728.           this.conn.stmt.nextRow();
  729.           return eval(this.conn.stmt.getColumn("CONTENTS").value);
  730.         }
  731.         catch(e) { debugExcept(e); return false; }
  732.       }
  733.     }
  734.  
  735.     function CBStrToLongColumnThing(s)
  736.     {
  737.       return { type: ADBC.SQLT_LONGVARCHAR, value: s, size: s.length };
  738.     }
  739.  
  740.     /* ADBC based annot store constructor
  741.     */
  742.     function ADBCAnnotStore(doc, user)
  743.     {
  744.       this.desc = CBgetTableDesc(doc, user);
  745.       this.enumerate = function(sorted)
  746.       {
  747.         return new ADBCAnnotEnumerator(this, sorted);
  748.       }
  749.       this.complete = function(toComplete)
  750.       {
  751.         var i;
  752.         var conn = CBconnect(this.desc,true);
  753.  
  754.         if (conn) 
  755.             {
  756.           for(i = 0; toComplete && i < toComplete.length; i++)
  757.           {
  758.             if(CBannotdata[toComplete[i].type])
  759.             {
  760.               var e;
  761.   
  762.               try
  763.               {
  764.                 conn.stmt.execute("select DATA from \"" + this.desc.tableName + "\" where PAGE = ? and NAME like ?;",
  765.                   toComplete[i].page, toComplete[i].name);
  766.                 conn.stmt.nextRow();
  767.                 var cos = Collab.newWrStreamToCosObj();
  768.  
  769.                 conn.stmt.getColumn("DATA", ADBC.Binary | ADBC.Stream, cos);
  770.                 CBannotSetData(toComplete[i], cos.getCosObj());
  771.               }
  772.               catch(e) 
  773.               { 
  774.                   debugExcept(e);
  775.                 return false;
  776.               }
  777.             }
  778.               }
  779.         } else return false;
  780.         return true;
  781.       }
  782.       this.update = function(toDelete, toAdd, toUpdate)
  783.       {
  784.         var i;
  785.         var e;
  786.         var conn = CBconnect(this.desc);
  787.         if(conn == null) return false;
  788.  
  789.         for(i = 0; toDelete && i < toDelete.length; i++)
  790.         {
  791.           try
  792.           {
  793.             conn.stmt.execute("delete from \"" + this.desc.tableName + "\" where PAGE = ? and NAME like ?;",
  794.               toDelete[i].page, toDelete[i].name);
  795.           }
  796.           catch(e) 
  797.           { 
  798.               debugExcept(e);
  799.             return false;
  800.           }
  801.         }
  802.         for(i = 0; toAdd && i < toAdd.length; i++)
  803.         {
  804.           try
  805.           {
  806.             conn.stmt.execute("insert into \"" + this.desc.tableName + "\" (AUTHOR, PAGE, NAME, CONTENTS, DATA) values (?, ?, ?, ?, ?);",
  807.               toAdd[i].author, toAdd[i].page, toAdd[i].name, CBStrToLongColumnThing(toAdd[i].toSource()), CBannotData(toAdd[i]));
  808.           }
  809.           catch(e) 
  810.           { 
  811.               debugExcept(e);
  812.             return false;
  813.           }
  814.         }
  815.         for(i = 0; toUpdate&& i < toUpdate.length; i++)
  816.         {
  817.           try
  818.           {      
  819.             conn.stmt.execute("update \"" + this.desc.tableName + "\" set CONTENTS = ?, DATA = ? where PAGE = ? and NAME like ?;",
  820.               CBStrToLongColumnThing(toUpdate[i].toSource()), CBannotData(toUpdate[i]), toUpdate[i].page, toUpdate[i].name);
  821.           }
  822.           catch(e) 
  823.           { 
  824.               debugExcept(e);
  825.             return false;
  826.           }
  827.         }
  828.         return true;
  829.       }
  830.     }
  831.  
  832.     /* Munge an URL such that Web Discussions won't put our data in the discussions pane
  833.     */
  834.     function WDmungeURL(url)
  835.     {
  836.         return url + "/ACData";
  837.     }
  838.  
  839.     /* Web discussions based annot enumerator constructor
  840.     */
  841.     function WDAnnotEnumerator(parent, sorted)
  842.     {
  843.     //  console.println("WDAnnotEnumerator(): Begin");
  844.  
  845.       this.parent = parent;
  846.       this.sorted = sorted;
  847.       this.next = function()
  848.       {
  849.         try
  850.         {
  851.             app.thermometer.begin();
  852.             app.thermometer.text = IDS_PROGRESS_FETCHING;
  853.  
  854.             if(!this.discussions)
  855.             {
  856.                   this.discussions = Discussions.getDiscussions(WDmungeURL(this.parent.doc.URL));
  857.  
  858.                 // always sort as our completion callback relies on a sorted list
  859.                   if(this.discussions)
  860.                   {
  861.                     this.discussions = isort(this.discussions, IDS_PROGRESS_SORTING);
  862.                     app.thermometer.duration = this.discussions.length;
  863.                   }
  864.                   this.index = 0;
  865.             }
  866.  
  867.             // skip non-Acro discussions
  868.             while(this.discussions && this.index < this.discussions.length && this.discussions[this.index] == "[Discussion]")
  869.                   app.thermometer.value = this.index++;
  870.  
  871.               app.thermometer.end();
  872.  
  873.             if(!this.discussions || this.index >= this.discussions.length)
  874.             {
  875.                   return false;
  876.             }
  877.             return eval(this.discussions[this.index++].Text);
  878.            }
  879.  
  880.         catch(e)
  881.         {
  882.               debugExcept(e);
  883.               app.thermometer.end();
  884.             return false;
  885.         }
  886.       } // next
  887.     }
  888.  
  889.     /* Web discussion based annot store constructor
  890.     */
  891.     function WDAnnotStore(doc, user)
  892.     {
  893.     //  console.println("WDAnnotStore(): Begin");
  894.  
  895.       this.doc = doc;
  896.       this.user = user;
  897.       this.enumerate = function(sorted)
  898.       {
  899.     //    console.println("WDAnnotStore.enumerate(): Begin");
  900.         return new WDAnnotEnumerator(this, sorted);
  901.       }
  902.       this.complete = function(toComplete)
  903.       {
  904.     //    console.show();
  905.     //    console.println("WDAnnotStore.toComplete(): Begin");
  906.  
  907.         var i,j;
  908.     //    console.println("get discussions for "+WDmungeURL(this.doc.URL));
  909.         var discussions = Discussions.getDiscussions(WDmungeURL(this.doc.URL));
  910.  
  911.         if (discussions == null) return false;
  912.  
  913.         if (discussions.length) 
  914.         {
  915.             // sort them to perform fast searches
  916.             // JS sort is a SLOW qsort... use our worst case N log ( N )
  917.             discussions = isort(discussions, IDS_PROGRESS_SORTING);
  918.  
  919.             try
  920.             {
  921.                 app.thermometer.begin();
  922.                 app.thermometer.text = IDS_PROGRESS_FETCHING_BIG;
  923.                 app.thermometer.duration = toComplete.length;
  924.  
  925.                 for(i = 0, j = 0; discussions && (i < toComplete.length) && (j < discussions.length); app.thermometer.value = ++i)
  926.                 {
  927.                     // create a string that'll look like the corresponding discussion
  928.                     var discString = Discussions.makeDiscussionString(toComplete[i].page, toComplete[i].name);
  929.  
  930.                     // keep skipping annots while they are "less" than the current one
  931.                     while(discString > discussions[j])
  932.                         j++;
  933.  
  934.                     // if we found it
  935.                     if(discString == discussions[j])
  936.                     {
  937.                         //console.println("found it - Annot to Complete " + i + " is in discussion slot " + j);
  938.                         //console.println("subject "+discussions[j].Subject);
  939.  
  940.                         /*
  941.                         ** We found the discussion, now gather replys which will
  942.                         ** contain the "data" for the stream
  943.                         */
  944.                         if (CBannotdata[toComplete[i].type])
  945.                             CBGetReplyChain(toComplete[i], discussions[j]);
  946.  
  947.                     }
  948.  
  949.                 }
  950.                 app.thermometer.end();
  951.             }
  952.             catch(e)
  953.             {
  954.                   debugExcept(e);
  955.                 app.thermometer.end();
  956.                 return false;
  957.             }
  958.         }
  959.         return true;
  960.       }
  961.       this.update = function(toDelete, toAdd, toUpdate)
  962.       {
  963.           var result = true;
  964.  
  965.     //    console.println("WDAnnotStore.update(): Begin");
  966.  
  967.         // get the list of discussions
  968.     //    console.println("WDAnnotStore.update(): get discussions "+WDmungeURL(this.doc.URL();
  969.         var discussions = Discussions.getDiscussions(WDmungeURL(this.doc.URL));
  970.         var i, j;
  971.  
  972.         // if we got any...
  973.         if(discussions && discussions.length)
  974.         {
  975.     //        console.println("WDAnnotStore.update(): got some " + discussions.length);
  976.             // sort them to perform fast searches
  977.             discussions = isort(discussions, IDS_PROGRESS_SORTING);
  978.  
  979.             // if we've got any to update
  980.             if(toUpdate && toUpdate.length)
  981.             {
  982.                 try
  983.                 {
  984.                     app.thermometer.begin();
  985.                     app.thermometer.text = IDS_PROGRESS_CHANGING;
  986.                     app.thermometer.duration = toUpdate.length;
  987.  
  988.                     for(i = 0, j = 0; i < toUpdate.length && j < discussions.length; app.thermometer.value = ++i)
  989.                     {
  990.                           // create a string that'll look like 
  991.                         // the corresponding discussion
  992.                           var discString = Discussions.makeDiscussionString(toUpdate[i].page, toUpdate[i].name);
  993.  
  994.                           // keep skipping annots while they are 
  995.                         // "less" than the current one
  996.                           while(discString > discussions[j]) j++;
  997.  
  998.                           // if we found it
  999.                           if(discString == discussions[j])
  1000.                           {
  1001.                             // then update it!
  1002.                             CBDeleteReplyChain(discussions[j]);
  1003.                             discussions[j].Delete();
  1004.  
  1005.                             var bookmark = Discussions.makeBookmark(toUpdate[i].page, toUpdate[i].name);
  1006.                             discussions[j] = Discussions.addDiscussion(WDmungeURL(this.doc.URL), "Markup", toUpdate[i].toSource(), bookmark);
  1007.                             CBPutReplyChain(discussions[j], bookmark, toUpdate[i]);
  1008.                             j++;
  1009.                           }
  1010.                     }
  1011.                     app.thermometer.end();
  1012.                 }
  1013.  
  1014.                 catch(e)
  1015.                 {
  1016.                     app.thermometer.end();
  1017.                     return false;
  1018.                 }
  1019.             }
  1020.  
  1021.             // delete is just like update
  1022.             if(toDelete && toDelete.length) 
  1023.             {
  1024.                 try
  1025.                 {
  1026.                     app.thermometer.begin();
  1027.                     app.thermometer.text = IDS_PROGRESS_DELETING;
  1028.                     app.thermometer.duration = toDelete.length;
  1029.                     for(i = 0, j = 0; i < toDelete.length && j < discussions.length; app.thermometer.value = ++i)
  1030.                     {
  1031.                           var discString = Discussions.makeDiscussionString(toDelete[i].page, toDelete[i].name);
  1032.  
  1033.                           while(discString > discussions[j])
  1034.                             j++;
  1035.  
  1036.                           if(discString == discussions[j])
  1037.                           {
  1038.                             CBDeleteReplyChain(discussions[j]);
  1039.                             discussions[j].Delete();
  1040.                             j++;
  1041.                           }
  1042.                     }
  1043.                     app.thermometer.end();
  1044.                 }
  1045.  
  1046.                 catch(e)
  1047.                 {
  1048.                     app.thermometer.end();
  1049.                     return false;
  1050.                 }
  1051.             }
  1052.         }
  1053.         if(toAdd && toAdd.length)
  1054.         {
  1055.             try
  1056.             {
  1057.                 app.thermometer.begin();
  1058.                 app.thermometer.text = IDS_PROGRESS_ADDING;
  1059.                 app.thermometer.duration = toAdd.length;
  1060.  
  1061.                 for(i = 0; toAdd && i < toAdd.length; app.thermometer.value = ++i)
  1062.                 {
  1063.                       var bookmark = Discussions.makeBookmark(toAdd[i].page, toAdd[i].name);
  1064.  
  1065.                       var discussion = Discussions.addDiscussion(WDmungeURL(this.doc.URL), "Markup", toAdd[i].toSource(), bookmark);
  1066.  
  1067.                     if(discussion == null)
  1068.                     {
  1069.                         result = false;
  1070.                         break;
  1071.                     }
  1072.  
  1073.                       if (CBannotdata[toAdd[i].type])
  1074.                     {
  1075.                         CBPutReplyChain(discussion, bookmark, toAdd[i]);
  1076.                     }
  1077.  
  1078.                 }
  1079.                 app.thermometer.end();
  1080.             }
  1081.  
  1082.             catch(e)
  1083.             {
  1084.                 app.thermometer.end();
  1085.                 return false;
  1086.             }
  1087.  
  1088.         }
  1089.         return result;
  1090.       }
  1091.     }
  1092.  
  1093.     /* Set up default annot stores */
  1094.     Collab.addAnnotStore("NONE", IDS_STORE_NONE,
  1095.         {create: function(doc, user, settings){ return null; }});
  1096.     Collab.setStoreNoSettings("NONE", true);
  1097.     if(typeof Discussions != "undefined")
  1098.     {
  1099.       Collab.addAnnotStore("WD", IDS_STORE_WEB_DISCUSSIONS,
  1100.             {create: function(doc, user, settings){ return new WDAnnotStore(doc, user); }});
  1101.         Collab.setStoreNoSettings("WD", true);
  1102.     }
  1103.     if(typeof ADBC != "undefined")
  1104.         Collab.addAnnotStore("DB", IDS_STORE_DATABASE,
  1105.             {create: function(doc, user, settings){ doc.collabDBRoot = settings; doc.collabDBFlags = CBFNiceTableName; return (settings && settings != "") ? new ADBCAnnotStore(doc, user) : null; }});
  1106.     Collab.addAnnotStore("DAVFDF", IDS_STORE_DAVFDF,
  1107.         {create: function(doc, user, settings){ return (settings && settings != "") ? new FSAnnotStore(doc, user, settings + doc.Collab.docID + "/", "CHTTP") : null; }});
  1108.     Collab.addAnnotStore("FSFDF", IDS_STORE_FSFDF,
  1109.         {create: function(doc, user, settings){ return (settings && settings != "") ? new FSAnnotStore(doc, user, settings + doc.Collab.docID + "/") : null; }});
  1110.     Collab.setStoreFSBased("FSFDF", true);
  1111.  
  1112.     // Web Discussion data block size
  1113.     Collab.wdBlockSize = 16384;
  1114.  
  1115.     // Add default state handlers -- this should go in a seperate file.
  1116.     Collab.addStateModel
  1117.     ({
  1118.         cName: "Review", 
  1119.         cUIName: IDS_ACTION_REVIEW, 
  1120.         oStates:
  1121.         { 
  1122.             "None": IDS_STATE_NONE,
  1123.             "Accepted":
  1124.             {
  1125.                 cUIName: IDS_STATE_ACCEPT,
  1126.                 cIconName: "C_Accept_Md_N.png"
  1127.             },
  1128.             "Rejected": 
  1129.             {
  1130.                 cUIName: IDS_STATE_REJECT,
  1131.                 cIconName: "C_Reject_Md_N.png"
  1132.             },
  1133.             "Cancelled": 
  1134.             {
  1135.                 cUIName: IDS_STATE_CANCELLED,
  1136.                 cIconName: "C_Cancel_Md_N.png"
  1137.             },
  1138.             "Completed": 
  1139.             {
  1140.                 cUIName: IDS_STATE_COMPLETED,
  1141.                 cIconName: "C_Complete_Md_N.png"
  1142.             }
  1143.         },
  1144.         cDefault: "None"
  1145.     });
  1146.  
  1147.     Collab.addStateModel
  1148.     ({
  1149.         cName: "CollabStatus", 
  1150.         cUIName: IDS_ACTION_COLLAB,
  1151.         oStates:
  1152.         {
  1153.             "Modified": IDS_STATE_COLLAB_ACTIVE,
  1154.             "Completed": IDS_STATE_COLLAB_COMPLETED
  1155.         },
  1156.         bHidden: true,
  1157.         cDefault: "Modified"
  1158.     });
  1159.  
  1160.     Collab.addStateModel
  1161.     ({
  1162.         cName: "Marked", 
  1163.         cUIName: IDS_ACTION_MARKED,
  1164.         oStates:
  1165.         {
  1166.             "Marked": IDS_STATE_MARKED,
  1167.             "Unmarked": IDS_STATE_UNMARKED
  1168.         },
  1169.         cDefault: "Unmarked",
  1170.         bHidden: true,
  1171.         bHistory: false
  1172.     });
  1173. }
  1174.  
  1175. /* E-mail ad-hoc workflow stuff */
  1176.  
  1177. // Send the current document out for review
  1178. function ANSendForReview(doc)
  1179. {
  1180.     if(!doc.dirty || app.alert({cMsg: IDS_SEND_FOR_REVIEW_DOC_IS_DIRTY, cTitle: IDS_SEND_FOR_REVIEW_TITLE_NONAME, nType: 2, nIcon: 1, oDoc: doc}) == 4)
  1181.     {
  1182.         // is there a valid e-mail address attached to the doc?
  1183.         var eaddr = identity.email;
  1184.         var explicitlyEntered = false;
  1185.  
  1186.         // Make sure the document gets saved if it's readonly
  1187.         if(doc.dirty && !doc.requestPermission(permission.document, permission.remove))
  1188.         {
  1189.             app.execMenuItem("Save");
  1190.             if(doc.dirty)
  1191.                 return 0; // Cancelled
  1192.         }
  1193.  
  1194.         // if not, try to get one
  1195.         if(!eaddr)
  1196.         {
  1197.             var emailRE = /^([a-zA-Z0-9_\-\.\/]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
  1198.  
  1199.             // pop the question
  1200.             do
  1201.             {
  1202.                 eaddr = app.response({    cQuestion: IDS_EMAIL_PLEASE, 
  1203.                                         cTitle: IDS_EMAIL_TITLE, 
  1204.                                         cDefault: IDS_EMAIL_BLANKNAME, 
  1205.                                         cLabel: IDS_EMAIL_LABEL});
  1206.                 if(eaddr != null && !eaddr.match(emailRE))
  1207.                     app.alert({cMsg: IDS_EMAIL_INVALID, cTitle: IDS_SEND_FOR_REVIEW_TITLE_NONAME, nIcon: 1, oDoc: doc});
  1208.             } while(eaddr != null && !eaddr.match(emailRE));
  1209.  
  1210.             // got a response?    pop it into the author info field
  1211.             if(eaddr != null)
  1212.                 identity.email = eaddr;
  1213.         }
  1214.  
  1215.         // shall we?
  1216.         var name;        
  1217.         var match = doc.path.match(/\/([^\/]*$)/);
  1218.  
  1219.         if (match && match.length == 2)
  1220.             name = match[1];
  1221.  
  1222.         if(!name)
  1223.             name = doc.path;
  1224.  
  1225.         // plop it into a localized string
  1226.         name = name.replace(/\.pdf\w*$/i, "");
  1227.         name = IDS_SEND_FOR_REVIEW_ATTACHMENT.replace(/\%pdfbase\%/g, name);
  1228.  
  1229.         if(eaddr != null)
  1230.         {
  1231.             var result;
  1232.             var info;
  1233.             var firstTime = true;
  1234.             var keepTrying = true;
  1235.             var startDate;
  1236.  
  1237.             //
  1238.             // If the submitForm fails, allow the user to correct the situation by 
  1239.             // bringing them back to our email dialog.  To get out of this while 
  1240.             // loop either a successful email must occur or the user must cancel
  1241.             // the dialog. 
  1242.             //
  1243.             while (keepTrying)
  1244.             {
  1245.                 if (firstTime)
  1246.                 {
  1247.                     info = doc.Collab.collectEmailInfo({
  1248.                         subj: IDS_SEND_FOR_REVIEW_SUBJ, 
  1249.                         msg: IDS_SEND_FOR_REVIEW_MSG,
  1250.                         inst1: IDS_SEND_FOR_REVIEW_INST1,
  1251.                         inst2: IDS_SEND_FOR_REVIEW_INST2,
  1252.                         title: IDS_SEND_FOR_REVIEW_TITLE,
  1253.                         attach: name,
  1254.                         reviewStatusDisabled: true,
  1255.                         helpID: "Dlg_SendEmailReview",
  1256.                         cCaption: IDS_SEND_FOR_REVIEW_GET_ADDRS_CAPTION, 
  1257.                         msgLabel: IDS_SEND_FOR_REVIEW_MSG_LABEL
  1258.                         });
  1259.                     firstTime = false;
  1260.  
  1261.                 } else {
  1262.                     info = doc.Collab.collectEmailInfo({
  1263.                         to: info[0],
  1264.                         cc: info[1],
  1265.                         bcc: info[2],
  1266.                         subj: info[3],
  1267.                         msg: info[4],
  1268.                         inst1: IDS_SEND_FOR_REVIEW_INST1,
  1269.                         inst2: IDS_SEND_FOR_REVIEW_INST2,
  1270.                         title: IDS_SEND_FOR_REVIEW_TITLE,
  1271.                         attach: name,
  1272.                         reviewStatusDisabled: true,
  1273.                         helpID: "Dlg_SendEmailReview",
  1274.                         cCaption: IDS_SEND_FOR_REVIEW_GET_ADDRS_CAPTION, 
  1275.                         msgLabel: IDS_SEND_FOR_REVIEW_MSG_LABEL
  1276.                         });
  1277.                 }
  1278.  
  1279.                 if (info)
  1280.                 {
  1281.                     startDate = new Date();
  1282.                     var url = "mailto:" + escape(info[0]) + "?" +
  1283.                         "cc=" + escape(info[1]) + "&" +
  1284.                         "bcc=" + escape(info[2]) + "&" +
  1285.                         "subject=" + escape(info[3]) + "&" +
  1286.                         "body=" + escape(info[4]) + "&" +
  1287.                         "ui=false";
  1288.  
  1289.                     var deadSource = info[5] ? ", " + info[5].toSource() : "";
  1290.                     var script = "if(app.viewerType.match(\"Exchange\") == null || app.viewerVersion < 6) { app.alert({cMsg: \"" + IDS_SEND_FOR_REVIEW_VERSION_ERR + "\", oDoc: doc}) } else { Collab.registerReview(this, " + eaddr.toSource() + ", \"\", " + info[0].toSource() + ", " + info[1].toSource() + ", \"\", " + startDate.toSource() + deadSource + ");}";
  1291.  
  1292.                     if (app.platform == "WIN")
  1293.                     {
  1294.                         if((typeof info[0] == "undefined") || info[0].length == 0)
  1295.                         {
  1296.                             app.alert({cMsg: IDS_SEND_FOR_REVIEW_NO_RECIPIENT, oDoc: doc});
  1297.                             return 0; // Cancelled
  1298.                         }
  1299.                     }
  1300.         
  1301.                     var e;
  1302.                     try
  1303.                     {
  1304.                         keepTrying = false;
  1305.                         result = doc.submitForm({cURL: url, bEmbedForm: true, oJavaScript: { After: script } });
  1306.                     }
  1307.                     catch(e)
  1308.                     {
  1309.                         app.alert({cMsg: e["message"], oDoc: doc});
  1310.                         keepTrying = true;
  1311. //                        app.alert({cMsg: IDS_SEND_FOR_REVIEW_PROBLEM, oDoc: doc});
  1312. //                        return 0; // Cancelled
  1313.                     }
  1314.                 }
  1315.                 else
  1316.                     keepTrying = false;
  1317.             }
  1318.  
  1319.             // Check the return value: submitForm can fail but not throw 
  1320.             // if it popped it's own UI.
  1321.             if(!result) return 0; // Cancelled
  1322.  
  1323.             var fdfName = name.replace(/\.pdf\w*$/i,"\.fdf");
  1324.             var alertText = IDS_SEND_FOR_REVIEW_CONFIRM_MSG.replace(/\%docname\%/g, fdfName);
  1325.             if (doc.Collab.isOutlook)
  1326.             {
  1327.                 doc.Collab.alertWithHelp(
  1328.                     { cMsg: alertText,
  1329.                     cTip: IDS_SEND_FOR_REVIEW_CONFIRM_TIP,
  1330.                     cTitle: IDS_SEND_FOR_REVIEW_CONFIRM_TITLE,
  1331.                     cPref: "Annots:OutgoingEmailNotification"}
  1332.                   );
  1333.             }
  1334.  
  1335.             // note that only the first part of this message is displayed.  If the full text
  1336.             // is displayed there is a bug in the alert and the OK button is not located 
  1337.             // properly and cannot get focus and thus the dialog cannot be dismissed.
  1338.             if(info[5])
  1339.                 Collab.registerReview(doc, null, "", info[0], info[1], info[2], startDate, info[5]);
  1340.             else
  1341.                 Collab.registerReview(doc, null, "", info[0], info[1], info[2], startDate);
  1342.  
  1343.             return 1; // Success
  1344.  
  1345.         } else return 0; // Cancelled - if (eaddr is not NULL)
  1346.     } else return 0; // Cancelled - if (!docIsDirty)
  1347.   return -1; // Failed
  1348. }
  1349.  
  1350. // Should send for review be enabled?
  1351. function ANSendForReviewEnabled(doc)
  1352. {
  1353.   event.rc = doc && !doc.external && doc.requestPermission(permission.annot, permission.canExport) && doc.requestPermission(permission.annot, permission.modify);
  1354. }
  1355.  
  1356. function ANSendCommentsToAuthor(doc)
  1357. {
  1358.     var eaddr = doc.Collab.initiatorEmail;
  1359.     var name = doc.info.title;  // first attempt: title info
  1360.  
  1361.     // second attempt: last component of path
  1362.     if(!name)
  1363.     {
  1364.         var match = doc.path.match(/\/([^\/]*$)/);
  1365.  
  1366.         if(match && match.length == 2)
  1367.         name = match[1];
  1368.     }
  1369.  
  1370.     // third attempt: path
  1371.     if(!name)
  1372.         name = doc.path;
  1373.  
  1374.     var attachname;
  1375.     var amatch = doc.path.match(/\/([^\/]*$)/);
  1376.     if(amatch && amatch.length == 2)
  1377.         attachname = amatch[1];
  1378.     if(!attachname)
  1379.         attachname = doc.path;
  1380.     var fdfName = attachname.replace(/\.pdf\w*$/i,"\.fdf");
  1381.  
  1382.     var dlgTitle = IDS_SEND_COMMENTS_TO_AUTHOR_TITLE.replace(/\{docname\}/g, name);
  1383.     var subject = IDS_SEND_COMMENTS_TO_AUTHOR_SUBJ.replace(/\{title\}/g, name);
  1384.     var mesg = IDS_SEND_COMMENTS_TO_AUTHOR_MSG.replace(/\{title\}/g, name);
  1385.     var firstTime = true;
  1386.     var keepTrying = true;
  1387.     var info;
  1388.     var result;
  1389.   
  1390.     fdfName = fdfName.replace(/\.fdf\w*$/i, "");
  1391.      fdfName = IDS_SEND_COMMENTS_ATTACHMENT.replace(/\%pdfbase\%/g, fdfName);
  1392.  
  1393.     //
  1394.     // Keep trying to send to send email until the user cancels the email 
  1395.     // review dialog or we successfully send the email
  1396.     //
  1397.     while (keepTrying)
  1398.     {
  1399.         if (firstTime)
  1400.         {
  1401.             info = doc.Collab.collectEmailInfo({
  1402.                 to: eaddr,
  1403.                 subj: subject,
  1404.                 msg: mesg,
  1405.                 title: dlgTitle,
  1406.                 attach: fdfName,
  1407.                 inst1: IDS_SEND_COMMENTS_TO_AUTHOR_INST1,
  1408.                 inst2: IDS_SEND_COMMENTS_TO_AUTHOR_INST2,
  1409.                 toDisabled: true,
  1410.                 ccDisabled: true,
  1411.                 bccDisabled: true,
  1412.                 deadDateDisabled: true,
  1413.                 reviewStatusDisabled: false,
  1414.                 helpID: "Dlg_ReplyReview",
  1415.                 cCaption: IDS_SEND_FOR_REVIEW_GET_ADDRS_CAPTION,
  1416.                 msgLabel: IDS_SEND_COMMENTS_TO_AUTHOR_MSG_LABEL
  1417.                 });
  1418.             firstTime = false;
  1419.         } else {
  1420.  
  1421.             info = doc.Collab.collectEmailInfo({
  1422.                 to: info[0],
  1423.                 cc: info[1],
  1424.                 bcc: info[2],
  1425.                 subj: info[3],
  1426.                 msg: info[4],
  1427.                 title: dlgTitle,
  1428.                 attach: fdfName,
  1429.                 inst1: IDS_SEND_COMMENTS_TO_AUTHOR_INST1,
  1430.                 inst2: IDS_SEND_COMMENTS_TO_AUTHOR_INST2,
  1431.                 toDisabled: true,
  1432.                 ccDisabled: true,
  1433.                 bccDisabled: true,
  1434.                 deadDateDisabled: true,
  1435.                 reviewStatusDisabled: false,
  1436.                 helpID: "Dlg_ReplyReview",
  1437.                 cCaption: IDS_SEND_FOR_REVIEW_GET_ADDRS_CAPTION,
  1438.                 msgLabel: IDS_SEND_COMMENTS_TO_AUTHOR_MSG_LABEL
  1439.                 });
  1440.         }
  1441.  
  1442.         if(info)
  1443.         {
  1444.             var url = "mailto:" + escape(info[0]) + "?" +
  1445.                 "cc=" + escape(info[1]) + "&" +
  1446.                 "bcc=" + escape(info[2]) + "&" +
  1447.                 "subject=" + escape(info[3]) + "&" +
  1448.                 "body=" + escape(info[4]) + "&" +
  1449.                 "ui=false";
  1450.  
  1451.             var e;
  1452.             try
  1453.             {
  1454.                 keepTrying = false;
  1455.                 result = doc.submitForm({
  1456.                     aFields: [],
  1457.                     bAnnotations: true,
  1458.                     bInclNMKey: true,
  1459.                     cURL: url,
  1460.                     bExclFKey: true
  1461.                     });
  1462.             }
  1463.             catch(e)
  1464.             {
  1465.                 keepTrying = true;
  1466.                 app.alert({cMsg: e["message"], oDoc: doc});
  1467.             }
  1468.         }
  1469.         else
  1470.             keepTrying = false;
  1471.     }
  1472.  
  1473.     if(!result) return;
  1474.  
  1475.     var alertText = IDS_SEND_FOR_REVIEW_CONFIRM_MSG.replace(/\%docname\%/g, fdfName);
  1476.     if (doc.Collab.isOutlook)
  1477.     {
  1478.         doc.Collab.alertWithHelp(
  1479.             { cMsg: alertText,
  1480.               cTip: IDS_SEND_FOR_REVIEW_CONFIRM_TIP,
  1481.               cTitle: IDS_SEND_FOR_REVIEW_CONFIRM_TITLE,
  1482.               cPref: "Annots:OutgoingEmailNotification"}
  1483.               );
  1484.     }
  1485.     Collab.setReviewRespondedDate(doc, new Date());
  1486. }
  1487.  
  1488. function ANSendCommentsToAuthorEnabled(doc)
  1489. {
  1490.   return (event.rc = doc && doc.Collab.initiatorEmail && doc.requestPermission(permission.annot, permission.canExport) && doc.requestPermission(permission.annot, permission.modify));
  1491. }
  1492.  
  1493. if(!app.viewerType.match(/Reader/))
  1494. {
  1495.     // Add the menu item
  1496.     app.addMenuItem({
  1497.       cName: "SendForReview",
  1498.       cUser: IDS_SEND_FOR_REVIEW,
  1499.       cParent: "File",
  1500.       nPos: "endOptimizeGroup",
  1501.       cExec: "ANSendForReview(event.target);",
  1502.       cEnable: "ANSendForReviewEnabled(event.target);",
  1503.       bPrepend: false
  1504.     });
  1505.  
  1506.     // Add the menu item
  1507.     app.addMenuItem({
  1508.       cName: "SendCommentsToAuthor",
  1509.       cUser: IDS_SEND_COMMENTS_TO_AUTHOR,
  1510.       cParent: "File",
  1511.       nPos: "endSendCommentsMenuItem",
  1512.       cExec: "ANSendCommentsToAuthor(event.target);",
  1513.       cEnable: "ANSendCommentsToAuthorEnabled(event.target);",
  1514.       bPrepend: true
  1515.     });
  1516. }
  1517.  
  1518. function ANDefaultInvite(doc)
  1519. {
  1520.   if(!doc.external)
  1521.   {
  1522.     return ANSendForReview(doc);
  1523.   }
  1524.   // if external, fall through to the default C++ implementation
  1525. };
  1526.  
  1527. Collab.invite = ANDefaultInvite;
  1528.  
  1529. function CBdef(a, b)
  1530. {
  1531.   return typeof a == "undefined" ? b : a;
  1532. }
  1533.  
  1534. function Matrix2D(a, b, c, d, h, v)
  1535. {
  1536.     this.a = CBdef(a, 1);
  1537.     this.b = CBdef(b, 0);
  1538.     this.c = CBdef(c, 0);
  1539.     this.d = CBdef(d, 1);
  1540.     this.h = CBdef(h, 0);
  1541.     this.v = CBdef(v, 0);
  1542.     this.fromRotated = function(doc, page)
  1543.     {
  1544.         page = CBdef(page, 0);
  1545.  
  1546.         var cropBox = doc.getPageBox("Crop", page);
  1547.         var mediaBox = doc.getPageBox("Media", page);
  1548.         var mbHeight = mediaBox[1] - mediaBox[3];
  1549.         var mbWidth = mediaBox[2] - mediaBox[0];
  1550.         var rotation = doc.getPageRotation(page);
  1551.         var m = new Matrix2D(1, 0, 0, 1, cropBox[0] - mediaBox[0], cropBox[3] - mediaBox[3]);
  1552.  
  1553.         if(rotation == 90)
  1554.             return this.concat(m.rotate(Math.asin(1.0)).translate(mbHeight, 0));
  1555.         else if(rotation == 180)
  1556.             return this.concat(m.rotate(2.0 * -Math.asin(1.0)).translate(mbWidth, mbHeight));
  1557.         else if(rotation == 270)
  1558.             return this.concat(m.rotate(-Math.asin(1.0)).translate(0, mbWidth));
  1559.         return this.concat(m);
  1560.     }
  1561.     this.transform = function(pts)
  1562.     {
  1563.         var result = new Array(pts.length);
  1564.  
  1565.         if(typeof pts[0] == "object")
  1566.             for(var n = 0; n < pts.length; n++)
  1567.                 result[n] = this.transform(pts[n]);
  1568.         else
  1569.             for(var n = 0; n + 1 < pts.length; n += 2)
  1570.             {
  1571.                 result[n] = this.a * pts[n] + this.c * pts[n + 1] + this.h;
  1572.                 result[n + 1] = this.b * pts[n] + this.d * pts[n + 1] + this.v;
  1573.             }
  1574.         return result;
  1575.     }
  1576.     this.concat = function(m)
  1577.     {
  1578.         return new Matrix2D(
  1579.             (this.a * m.a) + (this.b * m.c),
  1580.             (this.a * m.b) + (this.b * m.d),
  1581.             (this.c * m.a) + (this.d * m.c),
  1582.             (this.c * m.b) + (this.d * m.d),
  1583.             (this.h * m.a) + (this.v * m.c) + m.h,
  1584.             (this.h * m.b) + (this.v * m.d) + m.v);
  1585.     }
  1586.     this.invert = function()
  1587.     {
  1588.         var result = new Matrix2D;
  1589.         var q = this.b * this.c - this.a * this.d;
  1590.  
  1591.         if (q)
  1592.         {
  1593.             result.a = - this.d / q;
  1594.             result.b = this.b / q;
  1595.             result.c = this.c / q;
  1596.             result.d = - this.a / q;
  1597.             result.h = -(this.h * result.a + this.v * result.c);
  1598.             result.v = -(this.h * result.b + this.v * result.d);
  1599.         }
  1600.         return result;
  1601.     }
  1602.     this.translate = function(dx, dy)
  1603.     {
  1604.         return this.concat(new Matrix2D(1, 0, 0, 1, CBdef(dx, 0), CBdef(dy, 0)));
  1605.     }
  1606.     this.scale = function(sx, sy)
  1607.     {
  1608.         return this.concat(new Matrix2D(CBdef(sx, 1), 0, 0, CBdef(sy, 1), 0, 0));
  1609.     }
  1610.     this.rotate = function(t)
  1611.     {
  1612.         t = CBdef(t, 0);
  1613.         return this.concat(new Matrix2D(Math.cos(t), Math.sin(t), -Math.sin(t), Math.cos(t), 0, 0));
  1614.     }
  1615. }
  1616.